package edu.chl.da.ejb.core;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * This class respresent a travel-agent. Uses account to store more information.
 * @author Jakob
 */
@Entity
@Table(name = "TRAVELAGENT")
@NamedQueries({
    @NamedQuery(name = "Travelagent.findAll", query = "SELECT t FROM Travelagent t"),
    @NamedQuery(name = "Travelagent.findByAccount", query = "SELECT t FROM Travelagent t WHERE t.account = :account")})
public class Travelagent implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "ACCOUNT")
    private String account;
    @JoinColumn(name = "ACCOUNT", referencedColumnName = "USERNAME", insertable = false, updatable = false)
    @OneToOne(cascade = CascadeType.ALL, optional = false)
    private Account account1;

    public Travelagent() {
    }

    public Travelagent(String account) {
        this.account = account;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public Account getAccount1() {
        return account1;
    }

    public void setAccount1(Account account1) {
        this.account1 = account1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (account != null ? account.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Travelagent)) {
            return false;
        }
        Travelagent other = (Travelagent) object;
        if ((this.account == null && other.account != null) || (this.account != null && !this.account.equals(other.account))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.chl.da.ejb.core.Travelagent[account=" + account + "]";
    }

}
